package emulator;

import java.io.FileInputStream;

import emulator.GUI.VicUI;
import emulator.hardware.clock.ClockImplementation;
import emulator.hardware.memory.DebugMemoryBlock;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.commands.IllegalOpcodeException;

public class TestMain {

	/**
	 * @param args
	 * @throws EmulatorException 
	 */
	public static void main(String[] args) throws Exception {
		Cpu6502 cpu = new Cpu6502();
		DebugMemoryBlock memory = new DebugMemoryBlock(65536);
		memory.loadFromStream(new FileInputStream("data\\characters.901460-03.bin"), 0x8000, 0x1000);
		memory.loadFromStream(new FileInputStream("data\\pal.bin"), 0xC000, 0x4000);
		memory.enableReadonly(0x8000, 0x8FFF, true);
		memory.enableReadonly(0xC000, 0xFFFF, true);
		ClockImplementation clock = new ClockImplementation();
		cpu.attach(memory, clock);
		
		VicUI.run();
		
		try {
			cpu.reset();
			cpu.run();
		} catch(IllegalOpcodeException e) {
			cpu.setPC(cpu.getPC()-1);
			throw e;
		} finally {
			cpu.printState(System.out);
			System.out.println("Run for "+clock.getTicks()+" ticks.");
		}
	}

}
